package com.vrv.common.utils;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.OvershootInterpolator;
import android.view.animation.TranslateAnimation;

import com.vrv.common.Constants;

public class AnimationUtils {

	/**
	 * 动画至（tox，toY）
	 *
	 * @param view
	 */
	public static void slideView(final Context context, final View view, long duration, long offset, int x, final int toX, int y, final int toY) {
		TranslateAnimation translateAnimation = new TranslateAnimation(x, toX, y, toY);
		translateAnimation.setInterpolator(new OvershootInterpolator());
		translateAnimation.setDuration(duration);
		translateAnimation.setStartOffset(offset);
		translateAnimation.setFillAfter(true);
		translateAnimation.setAnimationListener(new AnimationListener() {

			@Override
			public void onAnimationStart(Animation animation) {
				view.setVisibility(View.INVISIBLE);
				view.invalidate();
			}

			@Override
			public void onAnimationRepeat(Animation animation) {
				Log.v(Constants.TAG, "{RepeatCount:" + animation.getRepeatCount() + "}");
			}

			@Override
			public void onAnimationEnd(Animation animation) {
				int left = view.getLeft() + toX;
				int top = view.getTop() + toY;
				int width = view.getWidth();
				int height = view.getHeight();
				view.clearAnimation();
				view.layout(left, top, left + width, top + height);
				view.setVisibility(View.VISIBLE);
				view.invalidate();
			}
		});
		view.startAnimation(translateAnimation);
	}
}
